package com.sskj.fabi.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.rxbus2.RxBus;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.fabi.bean.FabiPayWayBean;
import com.sskj.fabi.bean.PublishPrice;
import com.sskj.fabi.http.HttpConfig;
import com.sskj.fabi.ui.activity.PublishActivity;
import com.sskj.lib.RxBusCode;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;


public class PublishActivityPresenter extends BasePresenter<PublishActivity> {
    // 获取支付方式
    public void requsetPayWayList() {
        httpService.getPayWayList()
                .params("id", SPUtil.get(SPConfig.ID, ""))
                .execute(new JsonCallBack<HttpData<List<FabiPayWayBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<FabiPayWayBean>>> response) {
                        HttpData<List<FabiPayWayBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updatePayWay(httpData.getData());
                        }
                    }
                });

    }

    public void requsetPublish(boolean isBuy, String remark, String num, String min, String max, String price,
                               String payType, String pwd) {
        httpService.fabiPublish(isBuy, remark, num, min, max, price, payType, pwd)
                .execute(new JsonCallBack<HttpData>(this) {

                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {

                            RxBus.getDefault().send(RxBusCode.PUBLISH_SUCCESS);
                            mView.publishSuccess();
                        }
                    }
                });

    }

    // 获取单价
    public void requestUnitPrice() {
        OkGo.<HttpData<PublishPrice>>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_PRICELIMIT)
                .execute(new JsonCallBack<HttpData<PublishPrice>>() {

                    @Override
                    public void onSuccess(Response<HttpData<PublishPrice>> response) {

                        HttpData<PublishPrice> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updatePrice(httpData.getData().getValue());
                        }
                    }
                });
    }

    // 获取最小购买数量
    public void requestLimitNum() {
        OkGo.<HttpData<PublishPrice>>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_LIMIT_NUM)
                .execute(new JsonCallBack<HttpData<PublishPrice>>() {

                    @Override
                    public void onSuccess(Response<HttpData<PublishPrice>> response) {

                        HttpData<PublishPrice> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateLimitNum(httpData.getData().getValue());
                        }
                    }
                });
    }

}
